<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <script src="js/jquery-2.1.4.min.js"></script>
    <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <title>活动页面</title>
</head>
<%
    String code=request.getParameter("code");
    String state=request.getParameter("state");
    String openId=request.getParameter("openId");
%>
<body>
<input id="code" type="hidden" value="<%= code%>"/>
<input id="state" type="hidden" value="<%= state%>"/>
<input id="openId" type="hidden" value="<%= openId%>"/>

<script type="text/javascript">
    var zf_domain = 'http://m.52letsgo.cn'

    var code=1;
    var openId=1;
    var parentId=1;

    var shareLinkUrl = location.href.split('#')[0];//url

    if($("#state").val() != "null"){
        parentId=$("#state").val();
    }
    if($("#openId").val() !="null"){
        parentId =$("#openId").val();
    }
    if($("#code").val()!="null"){
        code = $("#code").val();
    }
    else if($("#code").val()=="null"){
        window.location.href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxf946190506655c2d&redirect_uri=http://m.52letsgo.cn/WeShare/WeiShareTest.jsp&response_type=code&scope=snsapi_userinfo&state="+parentId+"#wechat_redirect";
    }

    //获取签名
    $.ajax({
        type: "POST",
        url:zf_domain + '/WeShare/WeShare.do',
        data:{
            url: encodeURIComponent(shareLinkUrl),
            code:code
        },
        success: function(data){
            openId=data.openId;
            // 微信信息的以及调用的配置

            wx.config({
                debug: false,
                appId: 'wxf946190506655c2d',
                timestamp:data.timestamp,
                nonceStr:data.noncestr,
                signature:data.signature,
                jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone']
            });

            wx.ready(function(){
                // 获取“分享到朋友圈”按钮点击状态及自定义分享内容接口
                wx.onMenuShareTimeline({
                    type: "POST",
                    title: '分享到朋友圈', // 分享标题
                    link:"http://m.52letsgo.cn/WeShare/WeiShareTest.jsp?openId="+openId,
                    imgUrl: "http://images.cnblogs.com/cnblogs_com/liuhongfeng/737147/o_1442809977405.jpg",// 分享图标
                    success: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/keepId.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert(data.redEnvelope);
                            }
                        })
                    },
                    cancel: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/cancleShare.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert("已经取消分享了");
                            }
                        })
                    }
                });
                // 获取“分享给朋友”按钮点击状态及自定义分享内容接口
                wx.onMenuShareAppMessage({
                    title: '分享给朋友', // 分享标题
                    desc: "分享给朋友", // 分享描述
                    link:"http://m.52letsgo.cn/WeShare/WeiShareTest.jsp?openId="+openId,
                    imgUrl: "http://images.cnblogs.com/cnblogs_com/liuhongfeng/737147/o_QQ%E5%9B%BE%E7%89%8720151118180508.png", // 分享图标
                    type: 'link',// 分享类型,music、video或link，不填默认为link
                    success: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/keepId.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert(data.redEnvelope);
                            }
                        })
                    },
                    cancel: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/cancleShare.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert("已经取消分享了");
                            }
                        })
                    }
                });

                //获取“分享到QQ”按钮点击状态及自定义分享内容接口
                wx.onMenuShareQQ({
                    title: '分享到QQ', // 分享标题
                    desc: "分享到QQ", // 分享描述
                    link:"http://m.52letsgo.cn/WeShare/WeiShareTest.jsp?openId="+openId,
                    imgUrl: "http://images.cnblogs.com/cnblogs_com/liuhongfeng/737147/o_QQ%E5%9B%BE%E7%89%8720151118180508.png", // 分享图标
                    type: 'link',// 分享类型,music、video或link，不填默认为link
                    success: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/keepId.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert(data.redEnvelope);
                            }
                        })
                    },
                    cancel: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/cancleShare.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert("已经取消分享了");
                            }
                        })
                    }
                });

                //获取“分享到腾讯微博”按钮点击状态及自定义分享内容接口
                wx.onMenuShareWeibo({
                    title: '分享到微博', // 分享标题
                    desc: "分享到微博", // 分享描述
                    link:"http://m.52letsgo.cn/WeShare/WeiShareTest.jsp?openId="+openId,
                    imgUrl: "http://images.cnblogs.com/cnblogs_com/liuhongfeng/737147/o_QQ%E5%9B%BE%E7%89%8720151118180508.png", // 分享图标
                    type: 'link',// 分享类型,music、video或link，不填默认为link
                    success: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/keepId.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert(data.redEnvelope);
                            }
                        })
                    },
                    cancel: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/cancleShare.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert("已经取消分享了");
                            }
                        })
                    }
                });

                //获取“分享到QQ空间”按钮点击状态及自定义分享内容接口
                wx.onMenuShareQZone({
                    title: '分享到QQ空间', // 分享标题
                    desc: "分享到QQ空间", // 分享描述
                    link:"http://m.52letsgo.cn/WeShare/WeiShareTest.jsp?openId="+openId,
                    imgUrl: "http://images.cnblogs.com/cnblogs_com/liuhongfeng/737147/o_QQ%E5%9B%BE%E7%89%8720151118180508.png", // 分享图标
                    type: 'link',// 分享类型,music、video或link，不填默认为link
                    success: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/keepId.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert(data.redEnvelope);
                            }
                        })
                    },
                    cancel: function () {
                        $.ajax({
                            type: "POST",
                            url:zf_domain + '/WeShare/cancleShare.do',
                            data:{openId:openId,parentId:parentId,activityId:1},
                            success:function(data){
                                alert("已经取消分享了");
                            }
                        })
                    }
                });

            });
        },
        error:function (XMLHttpRequest, textStatus, errorThrown) {
            alert(XMLHttpRequest.responseText);
            alert(XMLHttpRequest.status);
            alert(XMLHttpRequest.readyState);
            alert(textStatus);
        }
    });
</script>
活动页面！
</body>
</html>